package reflection;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Main_Reflection {
    public static void main(String[] args) throws Throwable {
        InvocationHandler handler = new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Class<People> pCls = People.class;
                People p = pCls.newInstance();
                Method m = pCls.getMethod("hi",String.class);
                System.out.println(proxy.getClass());
                m.invoke(p, args);
                return null;
            }
        };

        I proxy = (I) Proxy.newProxyInstance(I.class.getClassLoader(), new Class[]{I.class}, handler);

        proxy.sayHi("+7");
//        proxy = new IImpl();
//        proxy = (IImpl) Proxy.newProxyInstance(proxy.getClass().getClassLoader(), proxy.getClass().getInterfaces(), handler);
//        proxy.sayHi("+9");
    }
}
